package com.eagle.util;

import cn.hutool.core.io.IoUtil;
import com.eagle.constant.Constant;
import com.google.common.base.Charsets;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @author qinlinsen
 */
public class PropertiesUtil {

    public static String getValueFromKey(String key) {
        final Properties properties = new Properties();
        InputStream stream = null;
        InputStreamReader reader = null;
        try {
            stream = PropertiesUtil.class.getClassLoader().getResourceAsStream(Constant.DEFAULT_PROPERTIES_FILE_NAME);
            reader = new InputStreamReader(stream, Charsets.UTF_8);
            properties.load(reader);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            IoUtil.close(stream);
            IoUtil.close(reader);
        }
        final Object result = properties.get(key);
        return String.valueOf(result);
    }

    public static void main(String[] args) throws Exception {
        final Object department = getValueFromKey("department");
        System.out.println(department);
    }

}

